﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Windows.Forms.DataVisualization.Charting;

namespace 花店管理系统.Order
{
    public partial class Proform : Form
    {
        public Proform()
        {
            InitializeComponent();
        }
        SqlDataAdapter daEmployee, daProform;
        DataSet ds = new DataSet();
        void init()
        {
            string str = "select t_name 员工姓名,count(o.O_id)订单数,sum(O_profit)总利润 " +
                "from Twoker e,Torder o where e.W_id=o.W_id and O_zhuangtai='已审核'" +
                "group by e.t_name";
            string sdr = "select * from Twoker where department='2'";
            daProform = new SqlDataAdapter(str, DB.cn);
            daEmployee = new SqlDataAdapter(sdr, DB.cn);
            daProform.Fill(ds, "Proform_info");
            daEmployee.Fill(ds, "employee_info");
        }

        private void dgvProform_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void Proform_Load(object sender, EventArgs e)
        {
            init();
            showAll();
            string[] Xname = new string[ds.Tables["Proform_info"].Rows.Count];
            double[] Yprofit = new double[ds.Tables["Proform_info"].Rows.Count];
            for(int i = 0; i < ds.Tables["Proform_info"].Rows.Count;i++)
            {
                Xname[i] = ds.Tables["Proform_info"].Rows[i][0].ToString();
                Yprofit[i] = double.Parse(ds.Tables["Proform_info"].Rows[i][2].ToString());
            }
            DisplayChart(Xname, Yprofit, "员工业绩图");
        }

        private void chart1_Click(object sender, EventArgs e)
        {

        }
        void DisplayChart(string[] xlabels, double[] yvalues,string serName)
        {
            chart1.Series.Clear();
            Series col = new Series(serName);
            for(int i=0;i<xlabels.Length;i++)
            {
                DataPoint dp = new DataPoint(i, yvalues[i]);
                dp.AxisLabel = xlabels[i];
                col.Points.Add(dp);
            }
            chart1.Series.Add(col);
            chart1.ChartAreas[0].AxisX.Interval = 1;
            chart1.Invalidate();
        }

        private void btnCance_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        void showAll()
        {
            DataView dvProform = new DataView(ds.Tables["Proform_info"]);
            dgvProform.DataSource = dvProform;
            DataView dvEmployee = new DataView(ds.Tables["employee_info"]);
            dgvEmployee.DataSource = dvEmployee;
        }
    }
}
